//回车键登陆
$(function(){
	$("#logsafecode").keyup(function(e){
	//console.info("bbbb");
        if(e.keyCode == 13){ 
            userLogin(); 
        } 
    });
});
//登录时的验证码
function changeCode(){
	$("#safecodeloginimg").attr("src","valiCodeImg.jsp?t="+new Date());
}

//用户登录
function userLogin(){
	var email=$.trim( $("#userEmail").val() );
	var pwd=$.trim( $("#myPassword").val() );
	var code=$.trim( $("#logsafecode").val() );
	
	if(email==""){
		alert("邮箱不能为空...");
		return;
	}
	
	if(pwd==""){
		alert("密码不能为空...");
		return;
	}
	
	if(code==""){
		alert("验证码不能为空...");
		return;
	}
	
	$.post("json/userInfoAction_userLogin",{"userInfo.email":email,"userInfo.pwd":pwd,"userInfo.flag":code},function(data){
		data=parseInt( $.trim(data.result) );
		console.info(data);
		if(data==1){
			alert("验证码错误...");
			$("#logsafecode").select();
		}else if(data==2){
			location.href="index.html";
		}else if(data==3){
			alert("邮箱或密码错误...");
		}
	});
}

function userOutLogin(){
	$.post("json/userInfoAction_userOutLogin",function(data){
		data=parseInt( $.trim(data.result) );
		if(data==1){
			str='您好！请 [<a class="yellowd1" rel="nofollow" href="login.html">登录</a>]<b class="borderdc">|</b>[<a class="yellowd1" rel="nofollow" href="reg.html" target="_blank">注册</a>]<b class="borderdc p_0_10">|</b>';
			$("#Gray7").html(str);
		}
	});
}

function getUserLoginInfo(){
	$.post("json/userInfoAction_getUserLogin",function(data){
		var str="";
		if(data.result==0){
			str='您好！[<a class="yellowd1" rel="nofollow" href="#">'+data.obj.uname+'</a>]<b class="borderdc">|</b>[<a class="yellowd1" rel="nofollow" href="javascript:userOutLogin()" >退出</a>]<b class="borderdc p_0_10">|</b>';
		}else{
			str='您好！请 [<a class="yellowd1" rel="nofollow" href="login.html">登录</a>]<b class="borderdc">|</b>[<a class="yellowd1" rel="nofollow" href="reg.html" target="_blank">注册</a>]<b class="borderdc p_0_10">|</b>';			
		}
		$("#Gray7").html(str);
	},"json");
}